#include <iostream>
#include <thread>
#include <vector>
#include <semaphore>
#include <bits/stdc++.h>
#include "smart_ptr.hpp"
using namespace std;

class A{
    public:
    virtual ~A(){
        cout<<"~A\n";
    }
};


class B:public A{
    public:
    virtual ~B()
    {
        cout<<"~B"<<endl;
    }

};

int main()
{
    counting_semaphore cnt(1);
    sharePtr<int> p (new int);
    vector<thread> td;
    for(int i = 0;i<100;i++)
    {
        td.push_back( thread( 
        [&p ,&cnt](){
            for(int i =0;i<10;i++)
            {
                //虽然这里用了只能指针，但是依然在使用多线程访问同一份临界资源时
                //还是需要加锁
                sharePtr<int> x = p;
                
                cnt.acquire();
                //p->
                cnt.release();
            }
        })
    );
    }
    for(auto &t:td)
    {
        t.join();
    }
    cout<<p.Usecount()<<endl;

    return 0;
}